#include <iostream>
#include <unistd.h>
#include <cstring>
#include <cerrno>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "Common.hpp"
using namespace std;

int main()
{
    //以读的方式，打开文件
    cout << "before open" << endl;
    int rfd = open("fifo_net",O_RDONLY);
    cout << "after open" << endl;

    //通信
    
    int command = 0;
    while(true)
    {
        int n = read(rfd,&command,sizeof(int));
        if(n == 0)
        {
            cout << "写端关闭了，我net退了" << endl;
            break;
        }
        if(command == 4)
        {
            cout << "server 要我net退出" << endl;
            break;
        }

        cout << "我读到了" << command << ",我正在执行net任务" << endl;
        
    }

    //关闭文件
    close(rfd);
    return 0;
}
